<?php
/*
	This SQL query will create the table to store your object.

	CREATE TABLE `credentials` (
	`credentialsid` int(11) NOT NULL auto_increment,
	`name` VARCHAR(255) NOT NULL,
	`all` BINARY NOT NULL,
	`contact_add` BINARY NOT NULL,
	`contact_edit` BINARY NOT NULL,
	`contact_delete` BINARY NOT NULL,
	`activity_add` BINARY NOT NULL,
	`activity_edit` BINARY NOT NULL,
	`activity_delete` BINARY NOT NULL,
	`company_add` BINARY NOT NULL,
	`company_edit` BINARY NOT NULL,
	`company_delete` BINARY NOT NULL,
	`crmuser_add` BINARY NOT NULL,
	`crmuser_edit` BINARY NOT NULL,
	`crmuser_delete` BINARY NOT NULL,
	`gotprorole_add` BINARY NOT NULL,
	`gotprorole_edit` BINARY NOT NULL,
	`gotprorole_delete` BINARY NOT NULL,
	`gotstudentactivity_add` BINARY NOT NULL,
	`gotstudentactivity_edit` BINARY NOT NULL,
	`gotstudentactivity_delete` BINARY NOT NULL,
	`supportcase_add` BINARY NOT NULL,
	`supportcase_edit` BINARY NOT NULL,
	`supportcase_delete` BINARY NOT NULL,
	`update_add` BINARY NOT NULL,
	`update_edit` BINARY NOT NULL,
	`update_delete` BINARY NOT NULL, PRIMARY KEY  (`credentialsid`)) ENGINE=MyISAM;
*/

/**
* <b>Credentials</b> class with integrated CRUD methods.
* @author Php Object Generator
* @version POG 3.0f / PHP5.1 MYSQL
* @see http://www.phpobjectgenerator.com/plog/tutorials/45/pdo-mysql
* @copyright Free for personal & commercial use. (Offered under the BSD license)
* @link http://www.phpobjectgenerator.com/?language=php5.1&wrapper=pdo&pdoDriver=mysql&objectName=Credentials&attributeList=array+%28%0A++0+%3D%3E+%27name%27%2C%0A++1+%3D%3E+%27all%27%2C%0A++2+%3D%3E+%27CRMUser%27%2C%0A++3+%3D%3E+%27contact_add%27%2C%0A++4+%3D%3E+%27contact_edit%27%2C%0A++5+%3D%3E+%27contact_delete%27%2C%0A++6+%3D%3E+%27activity_add%27%2C%0A++7+%3D%3E+%27activity_edit%27%2C%0A++8+%3D%3E+%27activity_delete%27%2C%0A++9+%3D%3E+%27company_add%27%2C%0A++10+%3D%3E+%27company_edit%27%2C%0A++11+%3D%3E+%27company_delete%27%2C%0A++12+%3D%3E+%27crmuser_add%27%2C%0A++13+%3D%3E+%27crmuser_edit%27%2C%0A++14+%3D%3E+%27crmuser_delete%27%2C%0A++15+%3D%3E+%27gotprorole_add%27%2C%0A++16+%3D%3E+%27gotprorole_edit%27%2C%0A++17+%3D%3E+%27gotprorole_delete%27%2C%0A++18+%3D%3E+%27gotstudentactivity_add%27%2C%0A++19+%3D%3E+%27gotstudentactivity_edit%27%2C%0A++20+%3D%3E+%27gotstudentactivity_delete%27%2C%0A++21+%3D%3E+%27supportcase_add%27%2C%0A++22+%3D%3E+%27supportcase_edit%27%2C%0A++23+%3D%3E+%27supportcase_delete%27%2C%0A++24+%3D%3E+%27update_add%27%2C%0A++25+%3D%3E+%27update_edit%27%2C%0A++26+%3D%3E+%27update_delete%27%2C%0A%29&typeList=array%2B%2528%250A%2B%2B0%2B%253D%253E%2B%2527VARCHAR%2528255%2529%2527%252C%250A%2B%2B1%2B%253D%253E%2B%2527BINARY%2527%252C%250A%2B%2B2%2B%253D%253E%2B%2527HASMANY%2527%252C%250A%2B%2B3%2B%253D%253E%2B%2527BINARY%2527%252C%250A%2B%2B4%2B%253D%253E%2B%2527BINARY%2527%252C%250A%2B%2B5%2B%253D%253E%2B%2527BINARY%2527%252C%250A%2B%2B6%2B%253D%253E%2B%2527BINARY%2527%252C%250A%2B%2B7%2B%253D%253E%2B%2527BINARY%2527%252C%250A%2B%2B8%2B%253D%253E%2B%2527BINARY%2527%252C%250A%2B%2B9%2B%253D%253E%2B%2527BINARY%2527%252C%250A%2B%2B10%2B%253D%253E%2B%2527BINARY%2527%252C%250A%2B%2B11%2B%253D%253E%2B%2527BINARY%2527%252C%250A%2B%2B12%2B%253D%253E%2B%2527BINARY%2527%252C%250A%2B%2B13%2B%253D%253E%2B%2527BINARY%2527%252C%250A%2B%2B14%2B%253D%253E%2B%2527BINARY%2527%252C%250A%2B%2B15%2B%253D%253E%2B%2527BINARY%2527%252C%250A%2B%2B16%2B%253D%253E%2B%2527BINARY%2527%252C%250A%2B%2B17%2B%253D%253E%2B%2527BINARY%2527%252C%250A%2B%2B18%2B%253D%253E%2B%2527BINARY%2527%252C%250A%2B%2B19%2B%253D%253E%2B%2527BINARY%2527%252C%250A%2B%2B20%2B%253D%253E%2B%2527BINARY%2527%252C%250A%2B%2B21%2B%253D%253E%2B%2527BINARY%2527%252C%250A%2B%2B22%2B%253D%253E%2B%2527BINARY%2527%252C%250A%2B%2B23%2B%253D%253E%2B%2527BINARY%2527%252C%250A%2B%2B24%2B%253D%253E%2B%2527BINARY%2527%252C%250A%2B%2B25%2B%253D%253E%2B%2527BINARY%2527%252C%250A%2B%2B26%2B%253D%253E%2B%2527BINARY%2527%252C%250A%2529
*/
include_once('class.pog_base.php');
class Credentials extends POG_Base
{
	public $credentialsId = '';

	/**
	 * @var VARCHAR(255)
	 */
	public $name;
	
	/**
	 * @var BINARY
	 */
	public $all;
	
	/**
	 * @var private array of CRMUser objects
	 */
	private $_crmuserList = array();
	
	/**
	 * @var BINARY
	 */
	public $contact_add;
	
	/**
	 * @var BINARY
	 */
	public $contact_edit;
	
	/**
	 * @var BINARY
	 */
	public $contact_delete;
	
	/**
	 * @var BINARY
	 */
	public $activity_add;
	
	/**
	 * @var BINARY
	 */
	public $activity_edit;
	
	/**
	 * @var BINARY
	 */
	public $activity_delete;
	
	/**
	 * @var BINARY
	 */
	public $company_add;
	
	/**
	 * @var BINARY
	 */
	public $company_edit;
	
	/**
	 * @var BINARY
	 */
	public $company_delete;
	
	/**
	 * @var BINARY
	 */
	public $crmuser_add;
	
	/**
	 * @var BINARY
	 */
	public $crmuser_edit;
	
	/**
	 * @var BINARY
	 */
	public $crmuser_delete;
	
	/**
	 * @var BINARY
	 */
	public $gotprorole_add;
	
	/**
	 * @var BINARY
	 */
	public $gotprorole_edit;
	
	/**
	 * @var BINARY
	 */
	public $gotprorole_delete;
	
	/**
	 * @var BINARY
	 */
	public $gotstudentactivity_add;
	
	/**
	 * @var BINARY
	 */
	public $gotstudentactivity_edit;
	
	/**
	 * @var BINARY
	 */
	public $gotstudentactivity_delete;
	
	/**
	 * @var BINARY
	 */
	public $supportcase_add;
	
	/**
	 * @var BINARY
	 */
	public $supportcase_edit;
	
	/**
	 * @var BINARY
	 */
	public $supportcase_delete;
	
	/**
	 * @var BINARY
	 */
	public $update_add;
	
	/**
	 * @var BINARY
	 */
	public $update_edit;
	
	/**
	 * @var BINARY
	 */
	public $update_delete;
	
	public $pog_attribute_type = array(
		"credentialsId" => array('db_attributes' => array("NUMERIC", "INT")),
		"name" => array('db_attributes' => array("TEXT", "VARCHAR", "255")),
		"all" => array('db_attributes' => array("TEXT", "BINARY")),
		"CRMUser" => array('db_attributes' => array("OBJECT", "HASMANY")),
		"contact_add" => array('db_attributes' => array("TEXT", "BINARY")),
		"contact_edit" => array('db_attributes' => array("TEXT", "BINARY")),
		"contact_delete" => array('db_attributes' => array("TEXT", "BINARY")),
		"activity_add" => array('db_attributes' => array("TEXT", "BINARY")),
		"activity_edit" => array('db_attributes' => array("TEXT", "BINARY")),
		"activity_delete" => array('db_attributes' => array("TEXT", "BINARY")),
		"company_add" => array('db_attributes' => array("TEXT", "BINARY")),
		"company_edit" => array('db_attributes' => array("TEXT", "BINARY")),
		"company_delete" => array('db_attributes' => array("TEXT", "BINARY")),
		"crmuser_add" => array('db_attributes' => array("TEXT", "BINARY")),
		"crmuser_edit" => array('db_attributes' => array("TEXT", "BINARY")),
		"crmuser_delete" => array('db_attributes' => array("TEXT", "BINARY")),
		"gotprorole_add" => array('db_attributes' => array("TEXT", "BINARY")),
		"gotprorole_edit" => array('db_attributes' => array("TEXT", "BINARY")),
		"gotprorole_delete" => array('db_attributes' => array("TEXT", "BINARY")),
		"gotstudentactivity_add" => array('db_attributes' => array("TEXT", "BINARY")),
		"gotstudentactivity_edit" => array('db_attributes' => array("TEXT", "BINARY")),
		"gotstudentactivity_delete" => array('db_attributes' => array("TEXT", "BINARY")),
		"supportcase_add" => array('db_attributes' => array("TEXT", "BINARY")),
		"supportcase_edit" => array('db_attributes' => array("TEXT", "BINARY")),
		"supportcase_delete" => array('db_attributes' => array("TEXT", "BINARY")),
		"update_add" => array('db_attributes' => array("TEXT", "BINARY")),
		"update_edit" => array('db_attributes' => array("TEXT", "BINARY")),
		"update_delete" => array('db_attributes' => array("TEXT", "BINARY")),
		);
	public $pog_query;
	
	
	/**
	* Getter for some private attributes
	* @return mixed $attribute
	*/
	public function __get($attribute)
	{
		if (isset($this->{"_".$attribute}))
		{
			return $this->{"_".$attribute};
		}
		else
		{
			return false;
		}
	}
	
	function Credentials($name='', $all='', $contact_add='', $contact_edit='', $contact_delete='', $activity_add='', $activity_edit='', $activity_delete='', $company_add='', $company_edit='', $company_delete='', $crmuser_add='', $crmuser_edit='', $crmuser_delete='', $gotprorole_add='', $gotprorole_edit='', $gotprorole_delete='', $gotstudentactivity_add='', $gotstudentactivity_edit='', $gotstudentactivity_delete='', $supportcase_add='', $supportcase_edit='', $supportcase_delete='', $update_add='', $update_edit='', $update_delete='')
	{
		$this->name = $name;
		$this->all = $all;
		$this->_crmuserList = array();
		$this->contact_add = $contact_add;
		$this->contact_edit = $contact_edit;
		$this->contact_delete = $contact_delete;
		$this->activity_add = $activity_add;
		$this->activity_edit = $activity_edit;
		$this->activity_delete = $activity_delete;
		$this->company_add = $company_add;
		$this->company_edit = $company_edit;
		$this->company_delete = $company_delete;
		$this->crmuser_add = $crmuser_add;
		$this->crmuser_edit = $crmuser_edit;
		$this->crmuser_delete = $crmuser_delete;
		$this->gotprorole_add = $gotprorole_add;
		$this->gotprorole_edit = $gotprorole_edit;
		$this->gotprorole_delete = $gotprorole_delete;
		$this->gotstudentactivity_add = $gotstudentactivity_add;
		$this->gotstudentactivity_edit = $gotstudentactivity_edit;
		$this->gotstudentactivity_delete = $gotstudentactivity_delete;
		$this->supportcase_add = $supportcase_add;
		$this->supportcase_edit = $supportcase_edit;
		$this->supportcase_delete = $supportcase_delete;
		$this->update_add = $update_add;
		$this->update_edit = $update_edit;
		$this->update_delete = $update_delete;
	}
	
	
	/**
	* Gets object from database
	* @param integer $credentialsId 
	* @return object $Credentials
	*/
	function Get($credentialsId)
	{
		$connection = Database::Connect();
		$this->pog_query = "select * from `credentials` where `credentialsid`='".intval($credentialsId)."' LIMIT 1";
		$cursor = Database::Reader($this->pog_query, $connection);
		while ($row = Database::Read($cursor))
		{
			$this->credentialsId = $row['credentialsid'];
			$this->name = $this->Unescape($row['name']);
			$this->all = $this->Unescape($row['all']);
			$this->contact_add = $this->Unescape($row['contact_add']);
			$this->contact_edit = $this->Unescape($row['contact_edit']);
			$this->contact_delete = $this->Unescape($row['contact_delete']);
			$this->activity_add = $this->Unescape($row['activity_add']);
			$this->activity_edit = $this->Unescape($row['activity_edit']);
			$this->activity_delete = $this->Unescape($row['activity_delete']);
			$this->company_add = $this->Unescape($row['company_add']);
			$this->company_edit = $this->Unescape($row['company_edit']);
			$this->company_delete = $this->Unescape($row['company_delete']);
			$this->crmuser_add = $this->Unescape($row['crmuser_add']);
			$this->crmuser_edit = $this->Unescape($row['crmuser_edit']);
			$this->crmuser_delete = $this->Unescape($row['crmuser_delete']);
			$this->gotprorole_add = $this->Unescape($row['gotprorole_add']);
			$this->gotprorole_edit = $this->Unescape($row['gotprorole_edit']);
			$this->gotprorole_delete = $this->Unescape($row['gotprorole_delete']);
			$this->gotstudentactivity_add = $this->Unescape($row['gotstudentactivity_add']);
			$this->gotstudentactivity_edit = $this->Unescape($row['gotstudentactivity_edit']);
			$this->gotstudentactivity_delete = $this->Unescape($row['gotstudentactivity_delete']);
			$this->supportcase_add = $this->Unescape($row['supportcase_add']);
			$this->supportcase_edit = $this->Unescape($row['supportcase_edit']);
			$this->supportcase_delete = $this->Unescape($row['supportcase_delete']);
			$this->update_add = $this->Unescape($row['update_add']);
			$this->update_edit = $this->Unescape($row['update_edit']);
			$this->update_delete = $this->Unescape($row['update_delete']);
		}
		return $this;
	}
	
	
	/**
	* Returns a sorted array of objects that match given conditions
	* @param multidimensional array {("field", "comparator", "value"), ("field", "comparator", "value"), ...} 
	* @param string $sortBy 
	* @param boolean $ascending 
	* @param int limit 
	* @return array $credentialsList
	*/
	function GetList($fcv_array = array(), $sortBy='', $ascending=true, $limit='')
	{
		$connection = Database::Connect();
		$sqlLimit = ($limit != '' ? "LIMIT $limit" : '');
		$this->pog_query = "select * from `credentials` ";
		$credentialsList = Array();
		if (sizeof($fcv_array) > 0)
		{
			$this->pog_query .= " where ";
			for ($i=0, $c=sizeof($fcv_array); $i<$c; $i++)
			{
				if (sizeof($fcv_array[$i]) == 1)
				{
					$this->pog_query .= " ".$fcv_array[$i][0]." ";
					continue;
				}
				else
				{
					if ($i > 0 && sizeof($fcv_array[$i-1]) != 1)
					{
						$this->pog_query .= " AND ";
					}
					if (isset($this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes']) && $this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes'][0] != 'NUMERIC' && $this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes'][0] != 'SET')
					{
						if ($GLOBALS['configuration']['db_encoding'] == 1)
						{
							$value = POG_Base::IsColumn($fcv_array[$i][2]) ? "BASE64_DECODE(".$fcv_array[$i][2].")" : "'".$fcv_array[$i][2]."'";
							$this->pog_query .= "BASE64_DECODE(`".$fcv_array[$i][0]."`) ".$fcv_array[$i][1]." ".$value;
						}
						else
						{
							$value =  POG_Base::IsColumn($fcv_array[$i][2]) ? $fcv_array[$i][2] : "'".$this->Escape($fcv_array[$i][2])."'";
							$this->pog_query .= "`".$fcv_array[$i][0]."` ".$fcv_array[$i][1]." ".$value;
						}
					}
					else
					{
						$value = POG_Base::IsColumn($fcv_array[$i][2]) ? $fcv_array[$i][2] : "'".$fcv_array[$i][2]."'";
						$this->pog_query .= "`".$fcv_array[$i][0]."` ".$fcv_array[$i][1]." ".$value;
					}
				}
			}
		}
		if ($sortBy != '')
		{
			if (isset($this->pog_attribute_type[$sortBy]['db_attributes']) && $this->pog_attribute_type[$sortBy]['db_attributes'][0] != 'NUMERIC' && $this->pog_attribute_type[$sortBy]['db_attributes'][0] != 'SET')
			{
				if ($GLOBALS['configuration']['db_encoding'] == 1)
				{
					$sortBy = "BASE64_DECODE($sortBy) ";
				}
				else
				{
					$sortBy = "$sortBy ";
				}
			}
			else
			{
				$sortBy = "$sortBy ";
			}
		}
		else
		{
			$sortBy = "credentialsid";
		}
		$this->pog_query .= " order by ".$sortBy." ".($ascending ? "asc" : "desc")." $sqlLimit";
		$thisObjectName = get_class($this);
		$cursor = Database::Reader($this->pog_query, $connection);
		while ($row = Database::Read($cursor))
		{
			$credentials = new $thisObjectName();
			$credentials->credentialsId = $row['credentialsid'];
			$credentials->name = $this->Unescape($row['name']);
			$credentials->all = $this->Unescape($row['all']);
			$credentials->contact_add = $this->Unescape($row['contact_add']);
			$credentials->contact_edit = $this->Unescape($row['contact_edit']);
			$credentials->contact_delete = $this->Unescape($row['contact_delete']);
			$credentials->activity_add = $this->Unescape($row['activity_add']);
			$credentials->activity_edit = $this->Unescape($row['activity_edit']);
			$credentials->activity_delete = $this->Unescape($row['activity_delete']);
			$credentials->company_add = $this->Unescape($row['company_add']);
			$credentials->company_edit = $this->Unescape($row['company_edit']);
			$credentials->company_delete = $this->Unescape($row['company_delete']);
			$credentials->crmuser_add = $this->Unescape($row['crmuser_add']);
			$credentials->crmuser_edit = $this->Unescape($row['crmuser_edit']);
			$credentials->crmuser_delete = $this->Unescape($row['crmuser_delete']);
			$credentials->gotprorole_add = $this->Unescape($row['gotprorole_add']);
			$credentials->gotprorole_edit = $this->Unescape($row['gotprorole_edit']);
			$credentials->gotprorole_delete = $this->Unescape($row['gotprorole_delete']);
			$credentials->gotstudentactivity_add = $this->Unescape($row['gotstudentactivity_add']);
			$credentials->gotstudentactivity_edit = $this->Unescape($row['gotstudentactivity_edit']);
			$credentials->gotstudentactivity_delete = $this->Unescape($row['gotstudentactivity_delete']);
			$credentials->supportcase_add = $this->Unescape($row['supportcase_add']);
			$credentials->supportcase_edit = $this->Unescape($row['supportcase_edit']);
			$credentials->supportcase_delete = $this->Unescape($row['supportcase_delete']);
			$credentials->update_add = $this->Unescape($row['update_add']);
			$credentials->update_edit = $this->Unescape($row['update_edit']);
			$credentials->update_delete = $this->Unescape($row['update_delete']);
			$credentialsList[] = $credentials;
		}
		return $credentialsList;
	}
	
	
	/**
	* Saves the object to the database
	* @return integer $credentialsId
	*/
	function Save($deep = true)
	{
		$connection = Database::Connect();
		$this->pog_query = "select `credentialsid` from `credentials` where `credentialsid`='".$this->credentialsId."' LIMIT 1";
		$rows = Database::Query($this->pog_query, $connection);
		if ($rows > 0)
		{
			$this->pog_query = "update `credentials` set 
			`name`='".$this->Escape($this->name)."', 
			`all`='".$this->Escape($this->all)."', 
			`contact_add`='".$this->Escape($this->contact_add)."', 
			`contact_edit`='".$this->Escape($this->contact_edit)."', 
			`contact_delete`='".$this->Escape($this->contact_delete)."', 
			`activity_add`='".$this->Escape($this->activity_add)."', 
			`activity_edit`='".$this->Escape($this->activity_edit)."', 
			`activity_delete`='".$this->Escape($this->activity_delete)."', 
			`company_add`='".$this->Escape($this->company_add)."', 
			`company_edit`='".$this->Escape($this->company_edit)."', 
			`company_delete`='".$this->Escape($this->company_delete)."', 
			`crmuser_add`='".$this->Escape($this->crmuser_add)."', 
			`crmuser_edit`='".$this->Escape($this->crmuser_edit)."', 
			`crmuser_delete`='".$this->Escape($this->crmuser_delete)."', 
			`gotprorole_add`='".$this->Escape($this->gotprorole_add)."', 
			`gotprorole_edit`='".$this->Escape($this->gotprorole_edit)."', 
			`gotprorole_delete`='".$this->Escape($this->gotprorole_delete)."', 
			`gotstudentactivity_add`='".$this->Escape($this->gotstudentactivity_add)."', 
			`gotstudentactivity_edit`='".$this->Escape($this->gotstudentactivity_edit)."', 
			`gotstudentactivity_delete`='".$this->Escape($this->gotstudentactivity_delete)."', 
			`supportcase_add`='".$this->Escape($this->supportcase_add)."', 
			`supportcase_edit`='".$this->Escape($this->supportcase_edit)."', 
			`supportcase_delete`='".$this->Escape($this->supportcase_delete)."', 
			`update_add`='".$this->Escape($this->update_add)."', 
			`update_edit`='".$this->Escape($this->update_edit)."', 
			`update_delete`='".$this->Escape($this->update_delete)."' where `credentialsid`='".$this->credentialsId."'";
		}
		else
		{
			$this->pog_query = "insert into `credentials` (`name`, `all`, `contact_add`, `contact_edit`, `contact_delete`, `activity_add`, `activity_edit`, `activity_delete`, `company_add`, `company_edit`, `company_delete`, `crmuser_add`, `crmuser_edit`, `crmuser_delete`, `gotprorole_add`, `gotprorole_edit`, `gotprorole_delete`, `gotstudentactivity_add`, `gotstudentactivity_edit`, `gotstudentactivity_delete`, `supportcase_add`, `supportcase_edit`, `supportcase_delete`, `update_add`, `update_edit`, `update_delete` ) values (
			'".$this->Escape($this->name)."', 
			'".$this->Escape($this->all)."', 
			'".$this->Escape($this->contact_add)."', 
			'".$this->Escape($this->contact_edit)."', 
			'".$this->Escape($this->contact_delete)."', 
			'".$this->Escape($this->activity_add)."', 
			'".$this->Escape($this->activity_edit)."', 
			'".$this->Escape($this->activity_delete)."', 
			'".$this->Escape($this->company_add)."', 
			'".$this->Escape($this->company_edit)."', 
			'".$this->Escape($this->company_delete)."', 
			'".$this->Escape($this->crmuser_add)."', 
			'".$this->Escape($this->crmuser_edit)."', 
			'".$this->Escape($this->crmuser_delete)."', 
			'".$this->Escape($this->gotprorole_add)."', 
			'".$this->Escape($this->gotprorole_edit)."', 
			'".$this->Escape($this->gotprorole_delete)."', 
			'".$this->Escape($this->gotstudentactivity_add)."', 
			'".$this->Escape($this->gotstudentactivity_edit)."', 
			'".$this->Escape($this->gotstudentactivity_delete)."', 
			'".$this->Escape($this->supportcase_add)."', 
			'".$this->Escape($this->supportcase_edit)."', 
			'".$this->Escape($this->supportcase_delete)."', 
			'".$this->Escape($this->update_add)."', 
			'".$this->Escape($this->update_edit)."', 
			'".$this->Escape($this->update_delete)."' )";
		}
		$insertId = Database::InsertOrUpdate($this->pog_query, $connection);
		if ($this->credentialsId == "")
		{
			$this->credentialsId = $insertId;
		}
		if ($deep)
		{
			foreach ($this->_crmuserList as $crmuser)
			{
				$crmuser->credentialsId = $this->credentialsId;
				$crmuser->Save($deep);
			}
		}
		return $this->credentialsId;
	}
	
	
	/**
	* Clones the object and saves it to the database
	* @return integer $credentialsId
	*/
	function SaveNew($deep = false)
	{
		$this->credentialsId = '';
		return $this->Save($deep);
	}
	
	
	/**
	* Deletes the object from the database
	* @return boolean
	*/
	function Delete($deep = false, $across = false)
	{
		if ($deep)
		{
			$crmuserList = $this->GetCrmuserList();
			foreach ($crmuserList as $crmuser)
			{
				$crmuser->Delete($deep, $across);
			}
		}
		$connection = Database::Connect();
		$this->pog_query = "delete from `credentials` where `credentialsid`='".$this->credentialsId."'";
		return Database::NonQuery($this->pog_query, $connection);
	}
	
	
	/**
	* Deletes a list of objects that match given conditions
	* @param multidimensional array {("field", "comparator", "value"), ("field", "comparator", "value"), ...} 
	* @param bool $deep 
	* @return 
	*/
	function DeleteList($fcv_array, $deep = false, $across = false)
	{
		if (sizeof($fcv_array) > 0)
		{
			if ($deep || $across)
			{
				$objectList = $this->GetList($fcv_array);
				foreach ($objectList as $object)
				{
					$object->Delete($deep, $across);
				}
			}
			else
			{
				$connection = Database::Connect();
				$pog_query = "delete from `credentials` where ";
				for ($i=0, $c=sizeof($fcv_array); $i<$c; $i++)
				{
					if (sizeof($fcv_array[$i]) == 1)
					{
						$pog_query .= " ".$fcv_array[$i][0]." ";
						continue;
					}
					else
					{
						if ($i > 0 && sizeof($fcv_array[$i-1]) !== 1)
						{
							$pog_query .= " AND ";
						}
						if (isset($this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes']) && $this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes'][0] != 'NUMERIC' && $this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes'][0] != 'SET')
						{
							$pog_query .= "`".$fcv_array[$i][0]."` ".$fcv_array[$i][1]." '".$this->Escape($fcv_array[$i][2])."'";
						}
						else
						{
							$pog_query .= "`".$fcv_array[$i][0]."` ".$fcv_array[$i][1]." '".$fcv_array[$i][2]."'";
						}
					}
				}
				return Database::NonQuery($pog_query, $connection);
			}
		}
	}
	
	
	/**
	* Gets a list of CRMUser objects associated to this one
	* @param multidimensional array {("field", "comparator", "value"), ("field", "comparator", "value"), ...} 
	* @param string $sortBy 
	* @param boolean $ascending 
	* @param int limit 
	* @return array of CRMUser objects
	*/
	function GetCrmuserList($fcv_array = array(), $sortBy='', $ascending=true, $limit='')
	{
		$crmuser = new CRMUser();
		$fcv_array[] = array("credentialsId", "=", $this->credentialsId);
		$dbObjects = $crmuser->GetList($fcv_array, $sortBy, $ascending, $limit);
		return $dbObjects;
	}
	
	
	/**
	* Makes this the parent of all CRMUser objects in the CRMUser List array. Any existing CRMUser will become orphan(s)
	* @return null
	*/
	function SetCrmuserList(&$list)
	{
		$this->_crmuserList = array();
		$existingCrmuserList = $this->GetCrmuserList();
		foreach ($existingCrmuserList as $crmuser)
		{
			$crmuser->credentialsId = '';
			$crmuser->Save(false);
		}
		$this->_crmuserList = $list;
	}
	
	
	/**
	* Associates the CRMUser object to this one
	* @return 
	*/
	function AddCrmuser(&$crmuser)
	{
		$crmuser->credentialsId = $this->credentialsId;
		$found = false;
		foreach($this->_crmuserList as $crmuser2)
		{
			if ($crmuser->crmuserId > 0 && $crmuser->crmuserId == $crmuser2->crmuserId)
			{
				$found = true;
				break;
			}
		}
		if (!$found)
		{
			$this->_crmuserList[] = $crmuser;
		}
	}
}
?>